from selenium.webdriver.common.by import By
from common.Utils import BlogDirver

class BlogDelete:
    url = "http://8.137.19.140:9090/blog_list.html"
    driver = BlogDirver.driver
    title = driver.title
    if not title=="博客列表页":
        driver.get(url)

    def DeleteTest(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > a").click()
        # 获取当前页面句柄
        curWindows = self.driver.current_window_handle
        # 获取所有页面句柄
        allWindows = self.driver.window_handles
        for windows in allWindows:
            if windows != curWindows:
                self.driver.switch_to.window(windows)
        title = self.driver.title

        assert title == "博客详情页"

        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(2)").click()
        alter = self.driver.switch_to.alert
        assert alter.text == "确定删除?"
        alter.accept()